load packages

library(pacman)
pacman::p_load(tidyverse, brms, ggeffects, tidybayes, ROCR, caret, interactions, install = TRUE)
devtools::install_github("hadley/emo")

define aesthetics

palette = c("#e64626", "#1985a1", "#4c5c68", "#FAC748")
palette_group = c(palette[2], palette[4])

plot_aes = theme_minimal() +
  theme(legend.position = "top",
        legend.text = element_text(size = 12),
        text = element_text(size = 16, family = "Futura Medium"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text = element_text(color = "black"),
        axis.line = element_line(colour = "black"),
        axis.ticks.y = element_blank())

define functions

make_table = function(data) {
    data %>%
      broom.mixed::tidy(conf.int = TRUE) %>%
      filter(effect == "fixed") %>%
      mutate(term = gsub("\\(Intercept\\)", "intercept", term),
             term = gsub("trial_condregulation", "trial condition (regulation)", term),
             term = gsub("trial_cond_recode", "trial condition (regulation)", term),
             term = gsub("dot_between_std_noc", "signature expression (between)", term),
             term = gsub("dot_within_std", "signature expression (within)", term),
             term = gsub("dot_sd", "signature expression variability", term),
             term = gsub("dist_expression_std", "signature expression modulation", term),
             term = gsub("mean_expression", "mean signature expression", term),
             term = gsub("regulation_expression", "signature expression (mindfulness)", term),
             term = gsub("reactivity_expression", "signature expression (reactivity)", term),
             term = gsub("active_weekon", "intervention week (on)", term),
             term = gsub("time_of_daymorning", "time of day (morning)", term),
             term = gsub("signal_count", "signal", term),
             term = gsub("SocialWeekendWeekend", "weekend", term),
             term = gsub("gender_f", "gender (female)", term),
             term = gsub(":", " x  ", term),
             `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high),) %>%
      select(term, `b [95% CI]`) %>%
      knitr::kable(digits = 2)
}

load and tidy data

  • remove trials missing stimulus information
    • the following participants had technical errors during all mindfulness trials: sub-MURIP012, sub-MURIP063, sub-MURIP078
  • remove trials in which the mean signal intensity of the brain map is +/- 3 SDs from the mean

task

task_data = read.csv("../data/task/cuereact_all062920.csv", stringsAsFactors = FALSE) %>%
  filter(grepl("rating", trial_type)) %>%
  select(pID, block_num, trial_num, trial_type, resp, rt, stim) %>%
  mutate(trial_cond = ifelse(grepl("friend3|friend4", trial_type), "regulation",
                      ifelse(grepl("friend1|friend2", trial_type), "up-regulation",
                      ifelse(grepl("mindful", trial_type), "regulation",
                      ifelse(grepl("nonalc", trial_type), "non-alcohol reactivity",
                      ifelse(grepl("rating_alc_react", trial_type), "reactivity", NA))))),
         trial_cond = factor(trial_cond, levels = c("non-alcohol reactivity", "reactivity", "regulation", "up-regulation"))) %>%
  rename("stimulus" = stim) %>%
  filter(!is.na(stimulus))

task_conditions = task_data %>%
  select(pID, trial_type) %>%
  unique() %>%
  filter(grepl("friend|mindful", trial_type) | pID %in% c("sub-MURIP012", "sub-MURIP063", "sub-MURIP078")) %>%
  mutate(condition = ifelse(grepl("friend", trial_type), "perspective", "mindfulness")) %>%
  select(-trial_type) %>%
  unique()

task_data_all = task_data %>%
  left_join(., task_conditions) %>%
  mutate(condition = ifelse(is.na(condition), "control", condition),
         trial_cond = factor(trial_cond, c("non-alcohol reactivity", "reactivity", "regulation", "up-regulation")))

task_mindfulness = task_data_all %>%
  filter(condition == "mindfulness")

dots

file_dir = "../data/dots"
file_pattern = "sub.*"
file_list = list.files(file_dir, pattern = file_pattern)

dots_tmp = data.frame()

for (file in file_list) {
  tmp = tryCatch(read.table(file.path(file_dir,file), fill = TRUE, header = TRUE, sep = ",") %>%
                    extract(file, c("pID", "beta"), ".*(sub-MURIC[0-9]{3}|sub-MURIP[0-9]{3})/(beta_[0-9]{4}).nii") %>%
                    mutate(stimulus = as.character(stimulus)), error = function(e) message(file))
  
  dots_tmp = rbind(dots_tmp, tmp)
  rm(tmp)
}

dots = dots_tmp %>%
  left_join(., task_conditions) %>%
  mutate(condition = ifelse(is.na(condition), "control", condition)) %>%
  group_by(condition) %>%
  filter(!stimulus == "nan") %>%
  mutate(sd3_signal = 3 * sd(mean_signal, na.rm = TRUE),
         grand_mean_signal = mean(mean_signal, na.rm = TRUE),
         outlier = ifelse(mean_signal > grand_mean_signal + sd3_signal, 1,
                   ifelse(mean_signal < grand_mean_signal - sd3_signal, 1, 0))) %>%
  select(-sd3_signal, -grand_mean_signal) %>%
  filter(!outlier == 1)

classifier data

classifier_data = read.csv("../data/mvpa/logistic_stats.csv", stringsAsFactors = FALSE) %>%
  rename("pID" = subjectID) %>%
    mutate(predicted_factor = ifelse(predicted > .5, "regulate", "react"),
           predicted_factor = as.factor(predicted_factor),
           actual_factor = ifelse(actual == 1, "regulate", "react"),
           actual_factor = as.factor(actual_factor))

merge and prep for modeling

  • filter out motion exclusions: sub-MURIC303
  • filter out reactivity to non-alcoholic beverage trials
  • recode trial condition as regulation = -.5 and reactivity = .5 to test relationship collapsed across conditions
  • create disaggregated_mindfulness dataset
    • dot_within_std = within-person centered level-1 signature expression variable; standardized across participants
    • dot_between_std = grand-mean centered level-2 signature expression variable; standardized across participants
merged = task_data_all %>%
  full_join(., dots) %>%
  filter(!pID == "sub-MURIC303") %>%
  filter(trial_cond %in% c("reactivity", "regulation")) %>%
  mutate(trial_cond_recode = ifelse(trial_cond == "regulation", .5, -.5),
         trial_cond = as.factor(as.character(trial_cond)))

between = merged %>%
  select(pID, dot, trial_cond, trial_cond_recode, condition) %>%
  group_by(pID, trial_cond, trial_cond_recode, condition) %>%
  summarize(dot_between = mean(dot, na.rm = TRUE)) %>%
  group_by(condition) %>%
  mutate(sd_dot = sd(dot_between, na.rm = TRUE),
         #dot_between_c = scale(dot_between, scale = FALSE, center = TRUE),
         #dot_between_std = dot_between_c / sd_dot,
         dot_between_std_noc = dot_between / sd_dot) %>%
  select(-sd_dot)

within = merged %>%
  select(pID, block_num, trial_num, dot, condition, trial_cond) %>%
  group_by(pID, condition) %>%
  mutate(dot_within_c = scale(dot, scale = FALSE, center = TRUE)) %>%
  group_by(condition) %>%
  mutate(sd_dot = sd(dot_within_c, na.rm = TRUE),
         dot_within_std = dot_within_c / sd_dot) %>%
  mutate(classifier_accuracy = ifelse(dot > 0 & trial_cond == "regulation", "hit",
                               ifelse(dot < 0 & trial_cond == "reactivity", "correct rejection",
                               ifelse(dot > 0 & trial_cond == "reactivity", "false alarm",
                               ifelse(dot < 0 & trial_cond == "regulation", "miss", NA))))) %>%
  select(-sd_dot)


disaggregated = merged %>%
  left_join(., between, by = c("pID", "condition", "trial_cond", "trial_cond_recode")) %>%
  left_join(., within, by = c("pID", "condition", "trial_num", "block_num", "trial_cond", "dot")) %>%
  filter(trial_cond %in% c("reactivity", "regulation"))

disaggregated_mindfulness = disaggregated %>%
  filter(condition == "mindfulness")

disaggregated_control = disaggregated %>%
  filter(condition == "control")

preregistered hypotheses

mindfulness signature development analyses

Here is the weight map from the MVPA analyses:

H1a

We expect that we will be able to train a classifier at the run level to distinguish mindfulness from uninstructed reactivity to alcohol cues with greater than chance accuracy decoding.

Results

✅ Average cross-validation decoding accuracy is greater than chance (though there’s lot of room for improvement).

ROC

classifier_data %>%
  do({
    condition = .$condition
    pred = prediction(.$predicted, .$actual)
    perf = performance(pred, measure = "tpr", x.measure = "fpr")
    data.frame(cut = perf@alpha.values[[1]],fpr = perf@x.values[[1]],tpr = perf@y.values[[1]])
  }) %>%
  ggplot(aes(fpr, tpr)) +
    geom_line(color = palette[4], size = 1) +
    geom_abline(intercept = 0, slope = 1) +
    scale_x_continuous(breaks = seq(0, 1, .2)) +
    scale_y_continuous(breaks = seq(0, 1, .2)) +
    labs(x = "\nfalse positive rate (1 - specificity)", y = "true positive rate (sensitivity)\n") +
    theme(legend.position = c(.8, .3),
          legend.spacing.y = unit(-.1, "cm")) +
   plot_aes

confusion matrix

caret::confusionMatrix(classifier_data$predicted_factor, classifier_data$actual_factor)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction react regulate
##   react       59       45
##   regulate    52       66
##                                           
##                Accuracy : 0.5631          
##                  95% CI : (0.4951, 0.6293)
##     No Information Rate : 0.5             
##     P-Value [Acc > NIR] : 0.03486         
##                                           
##                   Kappa : 0.1261          
##                                           
##  Mcnemar's Test P-Value : 0.54239         
##                                           
##             Sensitivity : 0.5315          
##             Specificity : 0.5946          
##          Pos Pred Value : 0.5673          
##          Neg Pred Value : 0.5593          
##              Prevalence : 0.5000          
##          Detection Rate : 0.2658          
##    Detection Prevalence : 0.4685          
##       Balanced Accuracy : 0.5631          
##                                           
##        'Positive' Class : react           
## 

H1b

Given that the classifier is developed at the run level, we will also confirm that the expression of the mindfulness signature is evident at the trial-level. That is, we expect the signature expression to be higher during mindfulness trials compared to reactivity trials.

Results

✅ Signature expression was higher on average during mindfulness trials than reactivity trials. Applying the signature as a classifier on a trial level, we also observed relatively high accuracy (70%) that is significantly above chance.

means

plot

data_means = merged %>%
  filter(condition == "mindfulness") %>%
  mutate(trial_cond = gsub("regulation", "mindfulness", trial_cond),
         trial_cond = factor(trial_cond, levels = c("reactivity", "mindfulness")))

data_means %>%
  ggplot(aes(trial_cond, dot, color = trial_cond, fill = trial_cond)) +
  stat_summary(fun.data = "mean_cl_boot", geom = "bar") +
  stat_summary(fun.data = "mean_cl_boot", geom = "errorbar", width = 0, color = "black") +
  scale_color_manual(name = "", values = palette) +
  scale_fill_manual(name = "", values = palette) +
  labs(x = "\ntrial type", y = "signature expression\n") +
  plot_aes +
  theme(legend.position = "none")

run model

table

make_table(mod_means)
term b [95% CI]
intercept -7.18 [-8.04, -6.31]
trial_condmindfulness 13.33 [12.15, 14.52]

summary

summary(mod_means)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: dot ~ trial_cond + (1 | pID) 
##    Data: data_means (Number of observations: 2265) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 37) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.43      0.32     0.01     1.15 1.00     1119     1124
## 
## Population-Level Effects: 
##                       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept                -7.18      0.44    -8.04    -6.31 1.00     4113
## trial_condmindfulness    13.33      0.62    12.15    14.52 1.00     3650
##                       Tail_ESS
## Intercept                 1158
## trial_condmindfulness     1309
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma    14.18      0.21    13.79    14.59 1.00     3349     1293
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

ROC

acc_line1 = data.frame(x = c(0, 1), y = c(1, 1))
acc_line2 = data.frame(y = c(0, 1), x = c(0, 0))

merged %>%
  filter(condition %in% c("mindfulness", "perspective")) %>%
  filter(!is.na(dot)) %>%
  mutate(actual = ifelse(trial_cond == "regulation", 1, 0)) %>%
  group_by(condition) %>%
  do({
    condition = .$condition
    pred = prediction(.$dot, .$actual)
    perf = performance(pred, measure = "tpr", x.measure = "fpr")
    data.frame(cut = perf@alpha.values[[1]],fpr = perf@x.values[[1]],tpr = perf@y.values[[1]])
  }) %>%
  ggplot(aes(fpr, tpr)) +
    geom_line(aes(color = condition), size = 1) +
    geom_abline(intercept = 0, slope = 1) +
    geom_line(data = acc_line1, aes(x, y)) +
    geom_line(data = acc_line2, aes(x, y)) +
    scale_color_manual(values = palette_group) +
    scale_x_continuous(breaks = seq(0, 1, .2)) +
    scale_y_continuous(breaks = seq(0, 1, .2)) +
    labs(x = "\nfalse positive rate (1 - specificity)", y = "true positive rate (sensitivity)\n") +
    plot_aes +
    theme(legend.position = "none",
          legend.spacing.y = unit(-.1, "cm"))

confusion matrix

conf_data = merged %>%
  filter(condition == "mindfulness") %>%
  filter(!is.na(dot)) %>%
  mutate(predicted = ifelse(dot > 0, "regulation",
                     ifelse(dot < 0, "reactivity", NA)),
         predicted = as.factor(predicted),
         trial_cond = as.factor(as.character(trial_cond)))

caret::confusionMatrix(conf_data$predicted, conf_data$trial_cond)
## Confusion Matrix and Statistics
## 
##             Reference
## Prediction   reactivity regulation
##   reactivity        836        336
##   regulation        348        745
##                                              
##                Accuracy : 0.698              
##                  95% CI : (0.6786, 0.7169)   
##     No Information Rate : 0.5227             
##     P-Value [Acc > NIR] : <0.0000000000000002
##                                              
##                   Kappa : 0.3951             
##                                              
##  Mcnemar's Test P-Value : 0.6741             
##                                              
##             Sensitivity : 0.7061             
##             Specificity : 0.6892             
##          Pos Pred Value : 0.7133             
##          Neg Pred Value : 0.6816             
##              Prevalence : 0.5227             
##          Detection Rate : 0.3691             
##    Detection Prevalence : 0.5174             
##       Balanced Accuracy : 0.6976             
##                                              
##        'Positive' Class : reactivity         
## 

craving: behavior only

run model

plot

behavior_mindfulness %>%
  spread_draws(b_Intercept, b_trial_condregulation) %>%
  mutate(reactivity = b_Intercept,
         mindfulness = b_Intercept + b_trial_condregulation) %>%
  gather(`trial type`, value, reactivity, mindfulness) %>%
  ggplot(aes(y = "", x = value, fill = `trial type`)) +
  stat_halfeye(alpha = .5) +
  scale_fill_manual(values = c(palette[2], palette[1])) +
  scale_y_discrete(expand = c(.1, .1)) +
  coord_cartesian(xlim = c(1.5, 2.5)) +
  labs(x = "\npredicted craving rating\n", y = "") + 
  plot_aes

behavior_mindfulness %>%
  spread_draws(b_Intercept, b_trial_condregulation) %>%
  mutate(reactivity = b_Intercept,
         mindfulness = b_Intercept + b_trial_condregulation) %>%
  gather(`trial type`, value, reactivity, mindfulness) %>%
  filter(`trial type` == "reactivity") %>%
  ggplot(aes(y = "", x = value, fill = `trial type`)) +
  stat_halfeye(alpha = .5) +
  scale_fill_manual(values = c(palette[1], palette[1])) +
  scale_y_discrete(expand = c(.1, .1)) +
  coord_cartesian(xlim = c(1.5, 2.5)) +
  labs(x = "\npredicted craving rating\n", y = "") + 
  plot_aes

table

make_table(behavior_mindfulness)
term b [95% CI]
intercept 2.00 [1.76, 2.23]
trial condition (regulation) -0.12 [-0.23, -0.01]

summary

summary(behavior_mindfulness)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: resp ~ 1 + trial_cond + (1 + trial_cond | pID) + (1 | stimulus) 
##    Data: disaggregated_mindfulness (Number of observations: 2214) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 37) 
##                                     Estimate Est.Error l-95% CI u-95% CI Rhat
## sd(Intercept)                           0.60      0.08     0.47     0.77 1.00
## sd(trial_condregulation)                0.21      0.07     0.06     0.34 1.00
## cor(Intercept,trial_condregulation)    -0.09      0.27    -0.53     0.53 1.00
##                                     Bulk_ESS Tail_ESS
## sd(Intercept)                            457      713
## sd(trial_condregulation)                 385      225
## cor(Intercept,trial_condregulation)     1407      521
## 
## ~stimulus (Number of levels: 72) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.39      0.04     0.32     0.47 1.01      631     1005
## 
## Population-Level Effects: 
##                      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept                2.00      0.12     1.76     2.23 1.01      289
## trial_condregulation    -0.12      0.05    -0.23    -0.01 1.00     1953
##                      Tail_ESS
## Intercept                 641
## trial_condregulation     1717
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.85      0.01     0.82     0.87 1.00     3292     1564
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

craving: mindfulness signature analyses

H2 & H3

H2:

We expect that people who have greater expression of the mindfulness signature on average (i.e., L2, between-person expression) will also have lower craving ratings on a trial-by-trial basis.

Results

✅ There is a statistically significant interaction between trial type and signature expression, such that people who have higher signature expression on average during mindfulness trials also report lower craving ratings, compared to during reactivity trials.


H3:

H3: We expect that trials with greater expression of the mindfulness signature compared to one’s average (i.e., L1, within-person expression) will be associated with lower craving ratings on a trial-by-trial basis.

Results

❌ Directionally, greater signature expression compared to one’s mean is associated with lower craving ratings on mindfulness trials, but this relationship is small and not statistically significant.

visualize raw data

averaged within participant
merged %>%
  filter(condition == "mindfulness") %>%
  group_by(pID, trial_cond) %>%
  mutate(mean_craving = mean(resp, na.rm = TRUE),
         mean_expression = mean(dot, na.rm = TRUE)) %>%
  select(pID, trial_cond, mean_expression, mean_craving) %>%
  unique() %>%
  ggplot(aes(mean_expression, mean_craving, color = trial_cond, fill = trial_cond)) +
  geom_jitter(alpha = .5, height = .1) +
  geom_smooth(method = "lm") +
  scale_color_manual(name = "trial type", values = palette) +
  scale_fill_manual(name = "trial type", values = palette) +
  labs(x = expression("\nreactivity   " * symbol('\254') * "   mean signature expression   " * symbol('\256') * "   mindfulness"),
       y = "mean craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

all data
merged %>%
  filter(condition == "mindfulness") %>%
  group_by(pID, trial_cond) %>%
  select(pID, trial_cond, dot, resp) %>%
  unique() %>%
  ggplot(aes(dot, resp, color = trial_cond, fill = trial_cond)) +
  geom_jitter(alpha = .5, height = .1) +
  geom_smooth(method = "lm") +
  scale_color_manual(name = "trial type", values = palette) +
  scale_fill_manual(name = "trial type", values = palette) +
  labs(x = expression("\nreactivity   " * symbol('\254') * "   mean signature expression   " * symbol('\256') * "   mindfulness"),
       y = "mean craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

participant slopes
disaggregated_mindfulness %>%
  ggplot(aes(dot, resp, color = trial_cond, fill = trial_cond)) +
  geom_smooth(aes(group = interaction(pID, trial_cond)), method = "lm", se = FALSE, size = .2) +
  geom_smooth(method = "lm") +
  scale_color_manual(name = "trial type", values = palette) +
  scale_fill_manual(name = "trial type", values = palette) +
  labs(x = expression("\nreactivity   " * symbol('\254') * "   signature expression   " * symbol('\256') * "   mindfulness"),
       y = "craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

run model

plots
between-person only

regulation

points_between = disaggregated_mindfulness %>%
  select(pID, resp, trial_cond, dot_between_std_noc) %>%
  group_by(pID, trial_cond, dot_between_std_noc) %>%
  summarize(resp = mean(resp, na.rm = TRUE)) %>%
  mutate(group = ifelse(trial_cond == "regulation", "mindfulness", "reactivity"),
         group = factor(group, levels = c("reactivity", "mindfulness")),
         type = "between-person") %>%
  rename("x" = dot_between_std_noc,
         "predicted" = resp)

vals = seq(-2,2,.2)
predicted = ggeffects::ggpredict(mod_h2_int, c("dot_between_std_noc [vals]", "trial_cond"), type = "fe") %>%
  data.frame() %>%
  mutate(type = "between-person") %>%
  mutate(group = ifelse(group == "regulation", "mindfulness", "reactivity"),
         group = factor(group, levels = c("reactivity", "mindfulness")))

predicted %>%
  filter(group == "mindfulness") %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_point(data = filter(points_between, group == "mindfulness"), alpha = .4, size = 2) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "trial type", values = palette[2]) +
  scale_color_manual(name = "trial type", values = palette[2]) +
  coord_cartesian(ylim = c(.5, 4)) +
  labs(x = expression("\nreactivity " * symbol('\254') * "   signature expression   " * symbol('\256') * " mindfulness"),
       y = "predicted craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

predicted %>%
  filter(group == "mindfulness") %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "trial type", values = palette[2]) +
  scale_color_manual(name = "trial type", values = palette[2]) +
  coord_cartesian(ylim = c(.5, 4)) +
  labs(x = expression("\nreactivity " * symbol('\254') * "   signature expression   " * symbol('\256') * " mindfulness"),
       y = "predicted craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

regulation and reactivity

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_point(data = points_between, alpha = .4, size = 2) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "trial type", values = palette) +
  scale_color_manual(name = "trial type", values = palette) +
  coord_cartesian(ylim = c(.5, 4)) +
  labs(x = expression("\nreactivity " * symbol('\254') * "   signature expression   " * symbol('\256') * " mindfulness"),
       y = "predicted craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "trial type", values = palette) +
  scale_color_manual(name = "trial type", values = palette) +
  coord_cartesian(ylim = c(.5, 4)) +
  labs(x = expression("\nreactivity " * symbol('\254') * "   signature expression   " * symbol('\256') * " mindfulness"),
       y = "predicted craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

within-person only
points_within = disaggregated_mindfulness %>%
  select(pID, resp, trial_cond, dot_within_std) %>%
  mutate(group = ifelse(trial_cond == "regulation", "mindfulness", "reactivity"),
         group = factor(group, levels = c("reactivity", "mindfulness")),
         type = "within-person") %>%
  rename("x" = dot_within_std,
         "predicted" = resp) %>%
  filter(x < 2 & x > -2)

vals = seq(-2,2,.2)
predicted = ggeffects::ggpredict(mod_h2_int, c("dot_within_std [vals]", "trial_cond"), type = "fe") %>%
  data.frame() %>%
  mutate(group = ifelse(group == "regulation", "mindfulness", "reactivity"),
         group = factor(group, levels = c("reactivity", "mindfulness")))

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_point(data = points_within, alpha = .4, size = 2, position = position_jitter(.1,.1)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "trial type", values = palette) +
  scale_color_manual(name = "trial type", values = palette) +
  coord_cartesian(ylim = c(.5, 3)) +
  labs(x = expression("\nreactivity   " * symbol('\254') * "   signature expression   " * symbol('\256') * "   mindfulness"),
       y = "predicted craving rating\n") +
  plot_aes +
  theme(legend.position = "top")

table
make_table(mod_h2_int)
term b [95% CI]
intercept 2.29 [1.97, 2.61]
trial condition (regulation) -0.15 [-0.52, 0.22]
signature expression (between) 0.28 [0.07, 0.51]
signature expression (within) -0.01 [-0.07, 0.05]
trial condition (regulation) x signature expression (between) -0.57 [-0.94, -0.22]
trial condition (regulation) x signature expression (within) -0.02 [-0.10, 0.06]
simple slopes
emmeans::emtrends(mod_h2_int, ~ trial_cond, var="dot_between_std_noc") %>%
    data.frame() %>%
    mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", dot_between_std_noc.trend, lower.HPD, upper.HPD)) %>%
  select(trial_cond, `b [95% CI]`)
emmeans::emtrends(mod_h2_int, ~ trial_cond, var="dot_within_std") %>%
    data.frame() %>%
    mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", dot_within_std.trend, lower.HPD, upper.HPD)) %>%
  select(trial_cond, `b [95% CI]`)
summary
summary(mod_h2_int)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: resp ~ 1 + trial_cond * dot_between_std_noc + trial_cond * dot_within_std + (1 + dot_within_std | pID) + (1 | stimulus) 
##    Data: disaggregated_mindfulness (Number of observations: 2213) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 37) 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## sd(Intercept)                     0.59      0.08     0.46     0.79 1.02
## sd(dot_within_std)                0.05      0.03     0.00     0.11 1.00
## cor(Intercept,dot_within_std)     0.06      0.42    -0.79     0.87 1.00
##                               Bulk_ESS Tail_ESS
## sd(Intercept)                      193      419
## sd(dot_within_std)                 462      791
## cor(Intercept,dot_within_std)     1598      905
## 
## ~stimulus (Number of levels: 72) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.39      0.04     0.32     0.47 1.00      491      673
## 
## Population-Level Effects: 
##                                          Estimate Est.Error l-95% CI u-95% CI
## Intercept                                    2.29      0.16     1.97     2.61
## trial_condregulation                        -0.15      0.19    -0.52     0.22
## dot_between_std_noc                          0.28      0.11     0.07     0.51
## dot_within_std                              -0.01      0.03    -0.07     0.05
## trial_condregulation:dot_between_std_noc    -0.57      0.18    -0.94    -0.22
## trial_condregulation:dot_within_std         -0.02      0.04    -0.10     0.06
##                                          Rhat Bulk_ESS Tail_ESS
## Intercept                                1.02      298      662
## trial_condregulation                     1.00      981     1321
## dot_between_std_noc                      1.00      866     1309
## dot_within_std                           1.00     1289     1178
## trial_condregulation:dot_between_std_noc 1.00     1190     1116
## trial_condregulation:dot_within_std      1.00     1489     1362
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.85      0.01     0.82     0.88 1.00     2313     1562
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

planned exploratory task analyses

E1

To examine divergent validity, we will apply the mindfulness signature to data from a separate group of participants who were instructed to use a different form of cognitive regulation (i.e., not mindfulness) that is not expected to rely on the same brain regions. We expect lower than chance accuracy decoding alcohol regulation versus reactivity trials.

I haven’t done what we laid out in our prereg yet, but here are the same analyses from H1b for the perspective taking group. The classifier is much less accurate in this group (accuracy = 54%) than in the mindfulness group.

means

plot

data_means = merged %>%
  filter(condition == "perspective")

data_means %>%
  ggplot(aes(trial_cond, dot, color = trial_cond, fill = trial_cond)) +
  stat_summary(fun.data = "mean_cl_boot", geom = "bar") +
  stat_summary(fun.data = "mean_cl_boot", geom = "errorbar", width = 0, color = "black") +
  scale_color_manual(name = "", values = palette) +
  scale_fill_manual(name = "", values = palette) +
  labs(x = "\ntrial type", y = "signature expression (dot product)\n") +
  plot_aes +
  theme(legend.position = "none")

run model

mod_e1 = brms::brm(dot ~ trial_cond + (1 | pID), data = data_means,
                   cores = 8, iter = 1000, silent = TRUE, seed = 6523)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
table
make_table(mod_e1)
term b [95% CI]
intercept -2.25 [-4.08, -0.51]
trial condition (regulation) 1.97 [0.74, 3.10]

summary

summary(mod_e1)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: dot ~ trial_cond + (1 | pID) 
##    Data: data_means (Number of observations: 1606) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 34) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     4.60      0.69     3.38     6.16 1.00      701      741
## 
## Population-Level Effects: 
##                      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept               -2.25      0.88    -4.08    -0.51 1.00      679
## trial_condregulation     1.97      0.60     0.74     3.10 1.00     3159
##                      Tail_ESS
## Intercept                 798
## trial_condregulation     1058
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma    12.35      0.22    11.93    12.79 1.00     4372     1471
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

ROC

acc_line1 = data.frame(x = c(0, 1), y = c(1, 1))
acc_line2 = data.frame(y = c(0, 1), x = c(0, 0))

merged %>%
  filter(condition %in% c("perspective", "mindfulness")) %>%
  filter(!is.na(dot)) %>%
  mutate(actual = ifelse(trial_cond == "regulation", 1, 0)) %>%
  group_by(condition) %>%
  do({
    condition = .$condition
    pred = prediction(.$dot, .$actual)
    perf = performance(pred, measure = "tpr", x.measure = "fpr")
    data.frame(cut = perf@alpha.values[[1]],fpr = perf@x.values[[1]],tpr = perf@y.values[[1]])
  }) %>%
  ggplot(aes(fpr, tpr)) +
    geom_line(aes(color = condition), size = 1) +
    geom_abline(intercept = 0, slope = 1) +
    geom_line(data = acc_line1, aes(x, y)) +
    geom_line(data = acc_line2, aes(x, y)) +
    scale_x_continuous(breaks = seq(0, 1, .2)) +
    scale_y_continuous(breaks = seq(0, 1, .2)) +
    scale_color_manual(name = "", values = palette_group) +
    labs(x = "\nfalse positive rate (1 - specificity)", y = "true positive rate (sensitivity)\n") +
    plot_aes +
    theme(legend.position = c(.8, .3),
        legend.spacing.y = unit(-.1, "cm"))

confusion matrix

conf_data = merged %>%
  filter(condition == "perspective") %>%
  filter(!is.na(dot)) %>%
  mutate(predicted = ifelse(dot > 0, "regulation",
                     ifelse(dot < 0, "reactivity", NA)),
         predicted = as.factor(predicted),
         trial_cond = as.factor(as.character(trial_cond)))

caret::confusionMatrix(conf_data$predicted, conf_data$trial_cond)
## Confusion Matrix and Statistics
## 
##             Reference
## Prediction   reactivity regulation
##   reactivity        468        417
##   regulation        336        385
##                                           
##                Accuracy : 0.5311          
##                  95% CI : (0.5064, 0.5558)
##     No Information Rate : 0.5006          
##     P-Value [Acc > NIR] : 0.007736        
##                                           
##                   Kappa : 0.0621          
##                                           
##  Mcnemar's Test P-Value : 0.003553        
##                                           
##             Sensitivity : 0.5821          
##             Specificity : 0.4800          
##          Pos Pred Value : 0.5288          
##          Neg Pred Value : 0.5340          
##              Prevalence : 0.5006          
##          Detection Rate : 0.2914          
##    Detection Prevalence : 0.5511          
##       Balanced Accuracy : 0.5311          
##                                           
##        'Positive' Class : reactivity      
## 

E2

We will explore whether expression of the mindfulness signature varies naturally during alcohol cue reactivity among participants not instructed to use mindfulness, and the degree to which expression is related to cravings.

Results

Between-person: ✅ ❌ People with stronger expression of the mindfulness signature on average also report lower craving ratings during exposure to alcohol cues. However, the credible interval includes zero.

Within-person: ✅ Stronger expression of the mindfulness signature compared to one’s average is associated with lower craving ratings during exposure to alcohol cues.

run model

mod_e2 = brms::brm(resp ~ dot_between_std_noc + dot_within_std +
                (1 + dot_within_std | pID) + (1 | stimulus), data = disaggregated_control,
                cores = 8, iter = 1000, silent = TRUE, seed = 6523)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1

plot

predicted = ggeffects::ggpredict(mod_e2, c("dot_between_std_noc [-2:2]"), type = "fe") %>%
  data.frame() %>%
  mutate(type = "between-person") %>%
  bind_rows(ggeffects::ggpredict(mod_e2, c("dot_within_std [-2:2]"), type = "fe") %>%
              data.frame() %>%
              mutate(type = "within-person"))

predicted %>%
  ggplot(aes(x, predicted, color = type, fill = type)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_fill_manual(name = "", values = palette[3:4]) +
  scale_color_manual(name = "", values = palette[3:4]) +
  labs(y = "predicated craving rating\n", x = "\nsignature expression (SD)") +
  plot_aes +
  theme(legend.position = "top")

table

make_table(mod_e2)
term b [95% CI]
intercept 1.88 [1.65, 2.11]
signature expression (between) -0.19 [-0.40, 0.01]
signature expression (within) -0.07 [-0.13, -0.02]

summary

summary(mod_e2)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: resp ~ dot_between_std_noc + dot_within_std + (1 + dot_within_std | pID) + (1 | stimulus) 
##    Data: disaggregated_control (Number of observations: 1785) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 39) 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## sd(Intercept)                     0.63      0.08     0.50     0.81 1.01
## sd(dot_within_std)                0.11      0.03     0.05     0.18 1.00
## cor(Intercept,dot_within_std)    -0.07      0.30    -0.66     0.49 1.00
##                               Bulk_ESS Tail_ESS
## sd(Intercept)                      553      719
## sd(dot_within_std)                 723      777
## cor(Intercept,dot_within_std)     1384     1150
## 
## ~stimulus (Number of levels: 72) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.28      0.03     0.22     0.36 1.00      836     1313
## 
## Population-Level Effects: 
##                     Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept               1.88      0.12     1.65     2.11 1.01      292      628
## dot_between_std_noc    -0.19      0.11    -0.40     0.01 1.01      557     1078
## dot_within_std         -0.07      0.03    -0.13    -0.02 1.00     2295     1773
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.88      0.01     0.85     0.91 1.00     3013     1518
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

E3

We will also explore the degree to which variability in mindfulness throughout the task is related to alcohol cravings on average. We expect that participants who more consistently express the mindfulness signature also report lower craving over the task.

Results

✅ ❌ Collapsed across trial types, higher variability in expression of the mindfulness signature is related to higher cravings. However, the credible interval includes zero.

run model

e3_data = merged %>%
  filter(condition == "mindfulness") %>%
  group_by(pID, trial_cond, trial_cond_recode) %>%
  mutate(dot_sd = sd(dot, na.rm = TRUE),
         mean_expression = mean(dot, na.rm = TRUE))

mod_e3 = brms::brm(resp ~ trial_cond_recode * dot_sd + mean_expression +
                (1 | pID) + (1 | stimulus), data = e3_data,
                cores = 8, iter = 1000, silent = TRUE, seed = 6523)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1

plot

predicted = ggeffects::ggpredict(mod_e3, c("dot_sd", "trial_cond_recode"), type = "fe") %>%
  data.frame() %>%
  mutate(group = ifelse(group == .5, "mindfulness", "reactivity"),
         group = factor(group, levels = c("reactivity", "mindfulness")))

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(aes(group = group), size = 1) +
  scale_fill_manual(name = "trial type", values = palette) +
  scale_color_manual(name = "trial type", values = palette) +
  labs(y = "predicated craving rating\n", x = "\nsignature expression variability") +
  plot_aes +
  theme(legend.position = "top")

table

make_table(mod_e3)
term b [95% CI]
intercept 1.65 [1.25, 2.06]
trial condition (regulation) -0.31 [-0.81, 0.19]
signature expression variability 0.02 [-0.01, 0.05]
mean signature expression 0.01 [-0.02, 0.04]
trial condition (regulation) x signature expression variability 0.01 [-0.02, 0.03]

summary

summary(mod_e3)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: resp ~ trial_cond_recode * dot_sd + mean_expression + (1 | pID) + (1 | stimulus) 
##    Data: e3_data (Number of observations: 2214) 
##   Draws: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup draws = 2000
## 
## Group-Level Effects: 
## ~pID (Number of levels: 37) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.58      0.08     0.45     0.76 1.01      289      469
## 
## ~stimulus (Number of levels: 72) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.39      0.04     0.32     0.48 1.01      360      717
## 
## Population-Level Effects: 
##                          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept                    1.65      0.21     1.25     2.06 1.02      440
## trial_cond_recode           -0.31      0.26    -0.81     0.19 1.00     1004
## dot_sd                       0.02      0.01    -0.01     0.05 1.00      683
## mean_expression              0.01      0.01    -0.02     0.04 1.00     1041
## trial_cond_recode:dot_sd     0.01      0.01    -0.02     0.03 1.00     1811
##                          Tail_ESS
## Intercept                     866
## trial_cond_recode            1271
## dot_sd                        811
## mean_expression              1134
## trial_cond_recode:dot_sd     1533
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.85      0.01     0.83     0.88 1.00     2618     1610
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).